package asimes.leetcode;

/**
 * Created by Asimes on 2016/10/21.
 */
public class ReverseVowelsofaString {
    public static void main(String[] args) {
        ReverseVowelsofaString rs = new ReverseVowelsofaString();
        long start = System.currentTimeMillis();
        String res = rs.reverseVowels("wevasvasdoviuasop[dvujasvnsakdjvnsvklnsdvkjsdnvsjkldvnasdvqpoiwdnvm,asdnv;klasdnvasddeleetcozxcvasdfqwevasvasdoviuasop[dvujasvnsakdjvnsvklnsdvkjsdnvsjkldvnasdvqpoiwdnvm,asdnv;klasdnvasddeleetcozxcvasdfqwevasvasdoviuasop[dvujasvnsakdjvnsvklnsdvkjsdnvsjkldvnasdvqpoiwdnvm,asdnv;klasdnvasddeleetcozxcvasdfqwevasvasdoviuasop[dvujasvnsakdjvnsvklnsdvkjsdnvsjkldvnasdvqpoiwdnvm,asdnv;klasdnvasdde" +
                "leetcozxcvasdfqwevasvasdoviuasop[dvujasvnsakdjvnsvklnsdvkjsdnvsjkldvnasdvqpoiwdnvm,asdnv;klasdnvasddeleetcozxcvasdfqwevasvasdoviuasop[dvujasvnsakdjvnsvklnsdvkjsdnvsjkldvnasdvqpoiwdnvm,asdnv;klasdnvasddeleetcozxcvasdfqwevasvasdoviuasop[dvujasvnsakdjvnsvklnsdvkjsdnvsjkldvnasdvqpoiwdnvm,asdnv;klasdnvasddeleetcozxcvasdfqwevasvasdoviuasop[dvujasvnsakdjvnsvklnsdvkjsdnvsjkldvnasdvqpoiwdnvm,asdnv;klasdnvasdde" +
                "leetcozxcvasdfqwevasvasdoviuasop[dvujasvnsakdjvnsvklnsdvkjsdnvsjkldvnasdvqpoiwdnvm,asdnv;klasdnvasddeleetcozxcvasdfqwevasvasdoviuasop[dvujasvnsakdjvnsvklnsdvkjsdnvsjkldvnasdvqpoiwdnvm,asdnv;klasdnvasddeleetcozxcvasdfqwevasvasdoviuasop[dvujasvnsakdjvnsvklnsdvkjsdnvsjkldvnasdvqpoiwdnvm,asdnv;klasdnvasddeleetcozxcvasdfqwevasvasdoviuasop[dvujasvnsakdjvnsvklnsdvkjsdnvsjkldvnasdvqpoiwdnvm,asdnv;klasdnvasddeleetcozxcvasdfqwevasvasdoviuasop[dvujasvnsakdjvnsvklnsdvkjsdnvsjkldvnasdvqpoiwdnvm,asdnv;klasdnvasdde" +
                "leetcozxcvasdfqwevasvasdoviuasop[dvujasvnsakdjvnsvklnsdvkjsdnvsjkldvnasdvqpoiwdnvm,asdnv;klasdnvasddeleetcozxcvasdfqwevasvasdoviuasop[dvujasvnsakdjvnsvklnsdvkjsdnvsjkldvnasdvqpoiwdnvm,asdnv;klasdnvasddeleetcozxcvasdfqwevasvasdoviuasop[dvujasvnsakdjvnsvklnsdvkjsdnvsjkldvnasdvqpoiwdnvm,asdnv;klasdnvasddeleetcozxcvasdfqwevasvasdoviuasop[dvujasvnsakdjvnsvklnsdvkjsdnvsjkldvnasdvqpoiwdnvm,asdnv;klasdnvasddeleetcozxcvasdfqwevasvasdoviuasop[dvujasvnsakdjvnsvklnsdvkjsdnvsjkldvnasdvqpoiwdnvm,asdnv;klasdnvasdde" +
                "leetcozxcvasdfqwevasvasdoviuasop[dvujasvnsakdjvnsvklnsdvkjsdnvsjkldvnasdvqpoiwdnvm,asdnv;klasdnvasddeleetcozxcvasdfqwevasvasdoviuasop[dvujasvnsakdjvnsvklnsdvkjsdnvsjkldvnasdvqpoiwdnvm,asdnv;klasdnvasddeleetcozxcvasdfqwevasvasdoviuasop[dvujasvnsakdjvnsvklnsdvkjsdnvsjkldvnasdvqpoiwdnvm,asdnv;klasdnvasddeleetcozxcvasdfqwevasvasdoviuasop[dvujasvnsakdjvnsvklnsdvkjsdnvsjkldvnasdvqpoiwdnvm,asdnv;klasdnvasddeleetcozxcvasdfqwevasvasdoviuasop[dvujasvnsakdjvnsvklnsdvkjsdnvsjkldvnasdvqpoiwdnvm,asdnv;klasdnvasdde"
        );
        long end = System.currentTimeMillis();

        System.out.println(end -start);
    }

    public String reverseVowels(String s) {
        StringBuilder sb = new StringBuilder(s);
        StringBuilder tmp = new StringBuilder();

        String ss = "AEIOUaeiou";
        for (int i = 0; i < sb.length(); i++) {
            if (ss.indexOf(sb.charAt(i)) >=0) {
                tmp.append(sb.charAt(i));
            }
        }
        int len = tmp.length();
        for (int i = 0; i < sb.length(); i++) {
            if (len>0&&ss.indexOf(sb.charAt(i)) >=0) {
                sb.setCharAt(i,tmp.charAt(--len));
            }
        }
        return sb.toString();
    }
}
